#include<bits/stdc++.h>
using namespace std;

int main()
{
	string str;
	cin>>str;
	int index1 = str.find(',');
	int index2 = str.rfind(',');
	string s(str, 0, index1);
	string s1(str, index1+1, index2-index1-1);
	string s2(str, index2+1, str.size()-index2-1);
	index1 = s.find(s1);
	index2 = s.rfind(s2);
	if(index1 == -1 || index2 == -1 || index1+s1.size() > index2)
		cout<<"-1";
	else
		cout<<index2-index1-s1.size();
    return 0;
}

